package com.yixun.qfbao.hander;

import java.util.ArrayList;
import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.yixun.qfbao.apidto.BatchUpdateCaseMemberDto;
import com.yixun.qfbao.apidto.CaseMemberWxStatus;
import com.yixun.qfbao.apidto.UpdateCaseMemberResDto;
import com.yixun.qfbao.dto.base.BaseRequestDTO;
import com.yixun.qfbao.dto.base.BaseResponseDTO;
import com.yixun.qfbao.hander.base.CommonAbstractHander;
import com.yixun.qfbao.vo.BatchUpdateCaseMemberVo;
import com.yixun.qfbao.xf.model.dto.CaseMemberDto;
import com.yixun.qfbao.xf.model.enums.ResultEnum;
import com.yixun.qfbao.xf.service.CaseMemberService;

/**
 * 批量修改案场员工的设置
 * @author zilong.liu
 *
 */
@Service
public class BatchUpdateCaseMemberHandler extends CommonAbstractHander{
	
	private static final Logger LOGGER = LoggerFactory.getLogger(BatchUpdateCaseMemberHandler.class);

	@Autowired
	CaseMemberService caseMemberService;
	
	/**
	 * 批量修改案场员工订阅信息
	 */
	@Override
	public BaseResponseDTO doBusiness(BaseRequestDTO reqDto) {
		BatchUpdateCaseMemberVo reqVo = (BatchUpdateCaseMemberVo)reqDto;
		BatchUpdateCaseMemberDto reqDto1 = reqVo.getParams();
		List<CaseMemberDto> caseMemberDtos = new ArrayList<>();
		for (CaseMemberWxStatus caseMemberWxStatus : reqDto1.getCaseMemberWxStatus()) {
			CaseMemberDto caseMemberDto = new CaseMemberDto();
			caseMemberDto.setWxMsgStatus(String.valueOf(caseMemberWxStatus.getWxMsgStatus()));
			caseMemberDto.setId(caseMemberWxStatus.getId());
			caseMemberDtos.add(caseMemberDto);
		}
        BaseResponseDTO<UpdateCaseMemberResDto> res = new BaseResponseDTO<UpdateCaseMemberResDto>();
        UpdateCaseMemberResDto resDto = new UpdateCaseMemberResDto();
        try{
        	
            caseMemberService.batchUpdateCaseMemberWxStatus(caseMemberDtos);
            resDto.setResult(ResultEnum.SUCCESS.getNo());
        }catch (Exception e){
            LOGGER.error("updateCaseMemberHander error: {}", e);
            resDto.setResult(ResultEnum.FAIL.getNo());
        }
        res.setResult(resDto.getResult());
        return res;
	}

}
